package com.teng.demo04.controller;

import com.teng.demo04.entity.User;
import com.teng.demo04.service.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("admin")
public class LoginController {
    @Autowired
    UserServiceImpl userService;

    @RequestMapping("/test")
    public ModelAndView test(){
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg","你成功了哈哈哈哈！？？？");
        mv.setViewName("test/testView");
        return mv;
    }

    @RequestMapping({"/","/index","/index.html"})
    public String index(){
        return "index";
    }

    @RequestMapping( "/login")
    public ModelAndView login(String userName,String password){
        ModelAndView mv = new ModelAndView();
        User user = userService.userLogin(userName);
        System.out.println(user);
        if (user != null && user.getPassword().equals(password)){
            mv.setViewName("book/book_list");
        }
        else{
            mv.addObject("msg","用户名或密码错误！");
            mv.setViewName("forward:index.html");
        }
        return mv;
    }
}